package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import entity.ActInfo;

public class ActInfoDao extends BaseDao{
			public List<ActInfo> getActinfoList(){
				 List<ActInfo> actinfos=new ArrayList();
				 Connection conn=super.getConn();
				 String sql="select key_id,name,count from act order by count";
				 try {
					Statement stm=conn.createStatement();
					ResultSet rs=stm.executeQuery(sql);
					int i=1;
					while(rs.next()){
						ActInfo act=new ActInfo();
						act.setNum(i);
						act.setId(rs.getInt(1));
						act.setName(rs.getString(2));
						act.setCount(rs.getInt(3));
						actinfos.add(act);
						i++;
					}
					super.closeConn(rs, stm, conn);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				 return actinfos;
			}
			public void updateCount(int count,int id){
				 Connection conn=super.getConn();
				 String sql="update act set count=? where key_id=?";
				 try {
					PreparedStatement pstm=conn.prepareStatement(sql);
					pstm.setInt(1, count);
					pstm.setInt(2, id);
					int result=pstm.executeUpdate();
					super.closeConn(null, pstm, conn);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			public static void main(String[] args) {
				ActInfoDao actdao=new ActInfoDao();
				System.out.println("size"+actdao.getActinfoList().size());
			}
}
